package cate.common.table.item.favorability.sheet;

import cate.common.table.ESheet;
import cate.common.table.item.favorability.row.FavorabilityAttrRow;
import cate.common.util.random.RWList;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class FavorabilityAttrSheet extends ESheet<FavorabilityAttrRow> {
    @Override
    public String getSheetName() {
        return "属性";
    }

    public FavorabilityAttrRow getAttr(int attrIdx){
        return get(attrIdx);
    }

    public FavorabilityAttrRow randomAttr(Map<Integer, Integer> records, Map<Integer, Integer> limits){
        List<FavorabilityAttrRow> randoms = getList().stream().
                filter(e -> e.getWeight() > 0 && records.getOrDefault(e.id, 0) < limits.getOrDefault(e.id, 0)).collect(Collectors.toList());
        if (randoms.isEmpty()) {
            return null;
        }
        RWList<FavorabilityAttrRow> rwList = new RWList<>();
        rwList.addAndSetup(randoms);
        return rwList.get();
    }
}
